#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <unordered_set>

using namespace std;

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        unordered_set<int> st;
        int idx = 0, ans = 0, i = 0;
        for (i = 0; i < s.size(); ++i) {
            if (!st.count(s[i]))
                st.emplace(s[i]);
            else {
                ans = max(ans, i - idx);
                while (st.count(s[i])) {
                    st.erase(s[idx++]);
                }
                //st.emplace(s[i]);
            }
        }
        return max(ans, i - idx);
    }
};


int main() {
    vector<int> nums = { 2,-3,0,-2,-5,-5,-4,1,2,-2,2,0,2,-4,5,5,-10 };
    Solution sol;
    sol.lengthOfLongestSubstring("bbbbb");
}